package org.eweb4j.solidbase.user.web.inter;

import javax.servlet.http.HttpSession;

import org.eweb4j.mvc.interceptor.Interceptor;
import org.eweb4j.solidbase.user.model.User;
import org.eweb4j.solidbase.user.model.UserCons;

/**
 * 登陆验证拦截器
 * 
 * @author weiwei
 * 
 */
public class LoginVerify extends Interceptor {

	public String intecept() {
		String error = null;
		HttpSession session = this.context.getRequest().getSession(true);
		String url = this.context.getRequest().getRequestURL().toString();
		String loginPath = url.replace(this.context.getUri(), "")
				+ UserCons.MODEL_NAME() + "/login";

		User user = (User) session.getAttribute("loginUser");
		if (user == null) {
			error = "<script>window.location='" + loginPath + "'</script>";
		}

		return error;
	}
}
